Creating .ics file from code sometimes givs "The file <filename>[<index>].ics" is not a valid intern

Posted by KaJo on Stack Overflow See other posts from Stack Overflow or by KaJo
Published on 2010-05-19T07:44:40Z Indexed on 2010/05/19 7:50 UTC
Read the original article Hit count: 371

Filed under:
|
|
|

Hi! I am building an ASP site where i use response.write to create an ics file where user can choose open or save dialog for the event. When the user choose open, outlook sometimes gives the error "The file [].ics" is not a valid internet Calender file"? It is always the same event that is written to the response. The code looks like this:

this.Response.ContentType = "text/calendar";
this.Response.AddHeader("Cache-Control", "no-cache, must-revalidate");            
this.Response.AddHeader("Pragma", "no-cache");
this.Response.Expires = -1;           
this.Response.AddHeader("Content-disposition", string.Format("attachment; filename={0}.ics",filename));
this.Response.Write("BEGIN:VCALENDAR");
this.Response.Write("\nVERSION:2.0");
this.Response.Write("\nMETHOD:PUBLISH");
this.Response.Write("\nBEGIN:VEVENT");
this.Response.Write("\nType:Single Meeting");
this.Response.Write("\nORGANIZER:MAILTO:" + organizer);
this.Response.Write("\nDTSTART:" + startDate.ToUniversalTime().ToString(DateFormat));
this.Response.Write("\nDTEND:" + endDate.ToUniversalTime().ToString(DateFormat));
this.Response.Write("\nLOCATION:" + location);
this.Response.Write("\nUID:" + Guid.NewGuid().ToString());
this.Response.Write("\nDTSTAMP:" + DateTime.Now.ToUniversalTime().ToString(DateFormat));
this.Response.Write("\nSUMMARY:" + summary);
this.Response.Write("\nDESCRIPTION:" + description);
this.Response.Write("\nPRIORITY:5");
this.Response.Write("\nCLASS:PUBLIC");
this.Response.Write("\nEND:VEVENT");
this.Response.Write("\nEND:VCALENDAR");
this.Response.End();

I usually get the error the first time I try to open the event in outlook, and the it works the second time?

Does anyone knows how to solve this problem?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about ics